using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_Stat : MonoBehaviour
{
    [SerializeField] private PlayerDataSO _playerDataSO;
    [SerializeField] private PlayerStatGroup _playerStatGroup;

    public PlayerStatGroup GetPlayerStatGroup() => _playerStatGroup;
    private void OnEnable()
    {
        EventCenter.AddEventListener<SlotScorllDataSO>(EventName.UI_AddScrollSlot, AddScrollSlot);
    }
    private void OnDisable()
    {
        EventCenter.RemoveEventListener<SlotScorllDataSO>(EventName.UI_AddScrollSlot, AddScrollSlot);
    }
    public float GetMaxHealth() => _playerStatGroup.maxHealth.GetValue();
    public float GetCritPower() => _playerStatGroup.critPower.GetValue();
    public float GetCritChance() => _playerStatGroup.critChance.GetValue();
    public float GetDamageBouns() => _playerStatGroup.damageBouns.GetValue();
    public float GetArmorCoefficient() => 1 + _playerStatGroup.armor.GetValue() * .1f;

    /// <summary>
    /// 属性增长
    /// </summary>
    /// <param name="increaseValue"></param>
    public void AddArmorStat(float increaseValue) => _playerStatGroup.armor.AddValue(increaseValue);
    public void AddDamageBounsStat(float increaseValue) => _playerStatGroup.damageBouns.AddValue(increaseValue);
    public void AddMaxHealthStat(float increaseValue) => _playerStatGroup.maxHealth.AddValue(increaseValue);

    public void AddScrollSlot(SlotScorllDataSO scorllDataSO)
    {
        _playerStatGroup.maxHealth.AddValue(scorllDataSO.maxHealth);

        _playerStatGroup.armor.AddValue(scorllDataSO.armor);

        _playerStatGroup.damageBouns.AddValue(scorllDataSO.damageBouns);

        _playerStatGroup.moveSpeed.AddValue(scorllDataSO.movementSpeed);

        _playerStatGroup.critChance.AddValue(scorllDataSO.critChance);

        _playerStatGroup.critPower.AddValue(scorllDataSO.critPower);
    }

    [ContextMenu("更新数据")]
    private void AppayDefaultStatSetup()
    {
        if (_playerDataSO == null)
            return;

        _playerStatGroup.maxHealth.SetBaseValue(_playerDataSO.maxHealth);

        _playerStatGroup.armor.SetBaseValue(_playerDataSO.armor);

        _playerStatGroup.damageBouns.SetBaseValue(_playerDataSO.damageBouns);

        _playerStatGroup.moveSpeed.SetBaseValue(_playerDataSO.movementSpeed);

        _playerStatGroup.critChance.SetBaseValue(_playerDataSO.critChance);

        _playerStatGroup.critPower.SetBaseValue(_playerDataSO.critPower);
    }
}
